GBML manual / Backgrounds

Zoomable backgrounds

A background picture the hardware can make bigger, smaller and turn - chosen room by room, because it costs that room two of its four background layers.

A picture that can zoom and turn

An ordinary background sits where you put it and can only slide about. A zoomable background is a picture the hardware can also make bigger, make smaller and turn, smoothly, as often as you like. It is what a map screen wants: zoom out to see the whole island, zoom in to read a village's name.

It is a picture and nothing more. It does not zoom the world. Sprites and instances stay the size they are, and the camera does not zoom either. Only this one picture grows, shrinks and turns.

The price: two of your four layers

The GBA can draw four ordinary background layers at once. To draw a picture that can zoom and turn, the console has to switch into a different display mode, and that mode only has two ordinary layers. The picture that zooms is a layer of its own kind, so it does not count as one of the two. But the other two are all that is left.

Ordinary layers you can showZoomable layers
A room without a zoomable background40
A room with one21

Whatever the room draws on its own uses these layers: its floor, its shroud if it is shrouded, the text box of a cutscene that plays there, and every background you make with background_create. A room with a floor and a shroud has already used both of its two.

Two things about that price are easy to miss.

It is your choice, room by room

Whether halving the layers is worth it depends on the game, and you are the one who knows. So the choice belongs to the room. In the Room Editor, open Room Properties and pick a picture under Zoomable background. Leave it on None and nothing changes.

The editor tells you what it costs right there, under the picker, in numbers: how many layers the room can show, how many it already uses and what is using them. If you pick a picture for a room that already needs more than two layers, it asks first and says exactly what will stop being drawn. The BG layers (room) gauge in the Budgets panel shows the same count, drawn against two for a room with a zoomable background and against four for one without. Validate and the build both raise an error when something the room certainly needs does not fit, for example a room with a floor, a shroud and a cutscene text box.

A map in a pause menu is the case this was made for. A pause screen needs few layers, so it can afford the price. Make the map its own room, give only that room a zoomable background, and send the player there with room_change when they press START. The room the player plays in keeps all four layers.

When there is no layer left

The engine never lets the console reach a state it cannot draw. Asked for a layer that is not there, it says no, politely, and carries on:

None of these is an error message in the game. They are quiet, which is why the editor counts for you: a room that certainly needs more than it has is an error before you build, and one that only might is a warning.

The picture

A zoomable picture is made differently from every other background, because the hardware reads it differently. An ordinary background picture cannot simply be switched over. The picture has to be prepared for this.

It has to beWhy
Square, exactly 128, 256, 512 or 1024 pixels on each sidethe hardware draws square maps of those sizes
8 bits per pixel: a picture with a palette of up to 256 colors, saved as an indexed .bmpthe zoomable layer always uses the big palette
made of at most 256 different 8x8 tilesits map has one byte for each cell, so it can point at 256 tiles, and no more
color 0 is see-throughas for every background

Tiles first. The picture is cut into 8x8 squares, and squares that are exactly the same are stored once. A flat blue sea is one tile used a hundred times, which costs almost nothing. A picture painted freehand with every pixel different has thousands. A 256x256 picture has 1,024 squares, so it needs at least three out of every four to be repeats of another. Draw with repeating tiles, flat areas and clear edges. A flipped copy of a tile counts as a different tile here, unlike an ordinary background. If the picture has too many, the build says how many it found, and Validate shows the same count.

Palette banks next. A zoomable picture uses one bank of the console's 16 background palette banks for every 16 colors, counting up to the highest color number its pixels use: a picture that only uses colors 0 to 15 takes one bank, one that reaches color 20 takes two. The room's own floor and other layers need banks of their own, so a picture that uses all 256 colors leaves them none. Keep the number of colors you really need, and put them first in the palette.

Making one. The Paint tab does not make zoomable pictures yet. Draw it in any image editor that can save an 8-bit indexed BMP, then:

  1. Save it as assets/tilesets/<name>.bmp in your project folder, with a file next to it called <name>.json that says { "type": "affine_bg" }.
  2. Add { "kind": "tileset", "name": "<name>" } to the assets list in game.gbabel.json, and reopen the project.

Or take one that is ready: the zoom_map example has a map picture you can bring into any project with + Add Existing... in the Paint tab's Sprites section, choosing Tileset or Background, so you can see exactly what a working one looks like. A zoomable picture does not appear anywhere a floor or tile sheet is chosen. Its one place is the Zoomable tick of the Room Editor's Tile Palette, in Backgrounds, with its own picture list.

Steering it

The picture is made for you when the room loads and let go of when it ends. Six calls steer that picture, so there is nothing to keep and nothing to check against nothing:

CallDoes
zoom_background_position(x, y)where the picture's top-left corner is on the screen
zoom_background_scale(scale)1 is real size, 2 twice as big, 0.5 half
zoom_background_rotation(degrees)turns it, counter-clockwise
zoom_background_focus(x, y)the screen spot that stays still while it zooms and turns
zoom_background_visible(bool)shows or hides it
zoom_background_priority(layer)which layer it is drawn on, 0 in front, 3 behind

Each does nothing in a room that has no zoomable background. A game in which no room has one cannot use them at all, and the checker says so.

The picture is screen-fixed: it stays where you put it on the screen while the camera moves. It starts at real size, with its top-left corner on the screen's top-left and the focus in the middle of the screen.

// Step event of the map screen's object. R zooms in, L zooms out, the d-pad moves around the map.
if (btn_held(BTN_R)) { xscale = clamp(xscale * 1.03, 0.5, 4); }
if (btn_held(BTN_L)) { xscale = clamp(xscale / 1.03, 0.5, 4); }
x += (btn_held(BTN_RIGHT) ? 2 : 0) - (btn_held(BTN_LEFT) ? 2 : 0);
y += (btn_held(BTN_DOWN) ? 2 : 0) - (btn_held(BTN_UP) ? 2 : 0);
zoom_background_scale(xscale);
zoom_background_position(-x, -y);

The object keeps the zoom in its own xscale and the place it is looking in its own x and y, so it needs no setup. Zooming grows the map out from the middle of the screen. Add zoom_background_focus to zoom toward a cursor instead.

The Game Boy Color

The Game Boy Color has no hardware for any of this. A game made for it that gives a room a zoomable background, or calls any zoom_background_ function, is refused when it is checked, with the same message every call a console cannot do gets. Use background_create, which every console has.

The limits, in one place

LimitValue
Ordinary background layers in a room with a zoomable background2
Ordinary background layers in a room without one4
Zoomable backgrounds per room1
Zoomable picture sizes128, 256, 512 or 1,024 pixels, square
Different tiles in a zoomable picture256
Scale1/16 to 16

Budgets explains the rest of the hardware's limits.

See also: BackgroundsBudgetsThe camerazoom_background_scalezoom_background_rotationzoom_background_positionzoom_background_focuszoom_background_visiblezoom_background_prioritybackground_create